<?php
//DatePeriod functions
class DatePeriod {
    /*
    * param $blnOnlyStartAndEnd only return an array contain the first start date and last end date
    */
    public static function getPeriods($blnOnlyStartAndEnd = false, $strInterval='month') {
        $objRequest = sfContext::getInstance()->getRequest();
        $strStartDate = $objRequest->getParameter("start_year").'-'.$objRequest->getParameter("start_month").'-01';
        $strEndDate   = $objRequest->getParameter("end_year").'-'.$objRequest->getParameter("end_month").'-01';

        $objDateCalculator = new DateTimeCalculator($strStartDate, "Y-m-d");
        $arrPeriods = $objDateCalculator->get_periods($strStartDate, $strEndDate, $strInterval);

        if($blnOnlyStartAndEnd
                && isset($arrPeriods[0]['start_date'])
                && isset($arrPeriods[count($arrPeriods) - 1]['end_date'])) {

            $strRealStartDate = $arrPeriods[0]['start_date'];
            $strRealEndDate   = $arrPeriods[count($arrPeriods) - 1]['end_date'];
            $arrPeriods = array('start_date' => $strRealStartDate,
                    'end_date'	 => $strRealEndDate,
            );
        }

        return $arrPeriods;
    }
}

?>